package com.wb.factory;

import com.wb.utils.FileName;
import org.apache.commons.configuration.Configuration;
import org.apache.commons.lang.StringUtils;

import java.io.File;

public class RdFileName extends FileNameFactory{
    @Override
    FileName createFileName(String template, String basePath, Configuration personalConfiguration, String className, String type) {
        String packageName=personalConfiguration.getString("package");
        String moduleName=personalConfiguration.getString("moduleName");
        String packagePath = "src" + File.separator + "main" + File.separator + "java" + File.separator;
        if (StringUtils.isNotBlank(packageName)) {
            packagePath += packageName.replace(".", File.separator) + File.separator + moduleName + File.separator;
        }
//            if (template.contains("MongoChildrenEntity.java.vm")) {
//                return packagePath + "entity" + File.separator + "inner" + File.separator + currentTableName+ File.separator + splitInnerName(className)+ "InnerEntity.java";
//            }
        String corePath = personalConfiguration.getString("core");
        String daoPath = personalConfiguration.getString("dao");
        String servicePath = personalConfiguration.getString("service");
        String webPath = personalConfiguration.getString("web");
        if (template.contains("Entity.java.vm")) {
            return new FileName(basePath+corePath  + File.separator+packagePath + "entity" + File.separator + className + ".java");
        }
        if (template.contains("Dto.java.vm")) {
            return new FileName(basePath+corePath  + File.separator+packagePath + "dto" + File.separator + className + "Dto.java");
        }
        if (template.contains("Vo.java.vm")) {
            return new FileName(basePath+corePath  + File.separator+packagePath + "vo" + File.separator + className + "Vo.java");
        }
        if (template.contains("VoMapper.java.vm")) {
            return new FileName(basePath+corePath  + File.separator+packagePath + "mapper" + File.separator + className + "Mapper.java");
        }
        if (template.contains("Dao.java.vm")) {
            return new FileName(basePath+daoPath  + File.separator+packagePath + "dao" + File.separator + className + "Dao.java");
        }
        if (template.contains("Repository.java.vm")) {
            return new FileName(basePath+daoPath  + File.separator+packagePath + "dao" + File.separator + className + "Repository.java");
        }
        if (template.contains("Service.java.vm")) {
            return new FileName(basePath+servicePath  + File.separator+packagePath + "service" + File.separator + className + "Service.java");
        }

        if (template.contains("ServiceImpl.java.vm")) {
            return new FileName(basePath+servicePath  + File.separator+packagePath + "service"  + File.separator + className + "ServiceImpl.java");
        }
        if (template.contains("Controller.java.vm")) {
            return new FileName(basePath+webPath  + File.separator+packagePath + "controller" + File.separator + className + "Controller.java");
        }
//        if (template.contains("Dao.xml.vm")) {
//            return new FileName("src" + File.separator + "main" + File.separator + "resources" + File.separator + "mapper" + File.separator + moduleName + File.separator + className + "Dao.xml");
//        }
        return null;
    }
}
